package com.example.test2018131425.controller;

import com.example.test2018131425.bean.UserBean;
import com.example.test2018131425.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;



@Controller
public class LoginController {
    @Resource
    UserService userService;

    @RequestMapping("/login")
    public String show(){
        return "login";
    }

    @RequestMapping(value = "/loginIn",method = RequestMethod.POST)
    public String login(String name, String password, HttpSession session){
        UserBean userBean = userService.loginIn(name,password);
        if (userBean != null){
            session.setAttribute("user",userBean);
            return "success";
        }else{
            return "loginError";
        }
    }

    @RequestMapping("/logout")
    public String logout(HttpSession session){
        session.invalidate();
        return "login";
    }
}
